package com.zz.service.iml;

import com.zz.dao.InDao;
import com.zz.dao.OutDao;
import com.zz.dao.PatientDao;
import com.zz.dao.WardDao;
import com.zz.pojo.In;
import com.zz.pojo.Patient;
import com.zz.service.OutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Copyright Zz
 * FileName: OutServiceIml
 * Author:   Zz
 * Date:     2023/6/90:00
 * Description:出院表业务层实现类
 * hISTORY:
 * <author>  <time>     <version>    <desc>
 * 作者姓名   修改时间       版本号       描述
 */
@Service
@Transactional
public class OutServiceIml implements OutService {
    @Autowired
    private PatientDao patientDao;

    @Autowired
    private InDao inDao;

    @Autowired
    private WardDao wardDao;

    @Autowired
    private OutDao outDao;

    @Override
    public int applyforOut(String ID) {
        Patient patient=patientDao.queryPatientByID(ID);
        if (patient!=null){
            In in=patient.getBed();
            inDao.deleteIn(in.getPatientId());
            patientDao.deletePatient(patient.getPatientId());
            wardDao.outWard(in.getAreaCode(),in.getRoomNumber(),in.getBedNumber());
            return outDao.applyforOut(patient);
        }else return 2;// 在院信息查无此病人
    }
}
